/**
 * 
 */
	function validateForm()
	{
		// Check fullfill
		var element=document.forms["inputActionUser"]["userid"].value;
		var error = "";
		if (element==null || element=="")
			error += "Please fill the userid\n"; 
			
		element=document.forms["inputActionUser"]["stockcode"].value;
		if (element==null || element=="")
			error += "Please fill the stockcode\n"; 
			
		element=document.forms["inputActionUser"]["price"].value;
		if (element==null || element=="")
			error += "Please fill the price\n";

		element=document.forms["inputActionUser"]["amount"].value;
		if (element==null || element=="")
			error += "Please fill the amount\n";	
		
		if (error != "")
			alert(error);
		else
			doTheActionInput();
	}

	function getRadioCheckedValue(radio_name)
	{
	   var oRadio = document.forms["inputActionUser"].elements[radio_name];
	 
	   for(var i = 0; i < oRadio.length; i++)
	   {
	      if(oRadio[i].checked)
	      {
	         return oRadio[i].value;
	      }
	   }
	   return '';
	}
	
	function doTheActionInput()
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  	xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
			  document.getElementById("erroramount").innerHTML=xmlhttp.responseText;
		    }
		  }
		  // Get the actionuser
		  var actionUser = getRadioCheckedValue("actionuser");
		var stockid = document.forms["inputActionUser"]["stockid"].value;
		var userid = document.forms["inputActionUser"]["userid"].value;
		var amount = document.forms["inputActionUser"]["amount"].value;
		var code = document.forms["inputActionUser"]["stockcode"].value;
		var price = document.forms["inputActionUser"]["price"].value;
		xmlhttp.open("GET","Controller.php?action=" + actionUser 
				+ "&stockid="+stockid
				+ "&userid="+userid
				+ "&amount="+amount
				+ "&code="+code
				+ "&price="+price,true);
		xmlhttp.send(null);
		document.forms["inputActionUser"]["reset"].click();
	}
	
	function showNameUser(userid)
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  	xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
		    		document.getElementById("showuserid").innerHTML=xmlhttp.responseText;
		    }
		  }
		xmlhttp.open("GET","Controller.php?action=showNameByUserID&userid="+userid,true);
		xmlhttp.send(null);
	}

	function showNameStock(code)
	{
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  	xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		xmlhttp.onreadystatechange=function()
		  {
		  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		    {
		    		document.getElementById("shownamestock").innerHTML=xmlhttp.responseText;
		    }
		  }
		xmlhttp.open("GET","Controller.php?action=showNameStock&code="+code,true);
		xmlhttp.send(null);
	}
	
	function checkPriceValid(price)
	{
		pricemax = document.getElementById("pricemax").value;
		pricemin = document.getElementById("pricemin").value;
		if (pricemax == null || pricemax == "")
		{
			document.getElementById("errorprice").innerHTML="ChÆ°a nhÃ¢Ì£p maÌƒ cÃ´Ì‰ phiÃªÌ�u";
		}
		else if (price < pricemin || price > pricemax)
		{
			document.getElementById("errorprice").innerHTML="NhÃ¢Ì£p sai giaÌ�";
		}
		else 
		{
			document.getElementById("errorprice").innerHTML="";
		}
	}

	function checkAmountValid(amount)
	{
		if (amount != "")
		{
			var action = "";
			if (document.forms["inputActionUser"].actionuser[0].checked)
				action = "sell"
			else
				action = "buy";
			var url = "";
			if (action == "buy")
			{
				url = "action=checkUserBuy&price=" + document.forms["inputActionUser"]["price"].value 
					+ "&amount=" + amount 
					+ "&userid=" + document.forms["inputActionUser"]["userid"].value;
			}
			else
			{
				url = "action=checkUserSell&stockid=" + document.forms["inputActionUser"]["stockid"].value 
				+ "&amount=" + amount 
				+ "&userid=" + document.forms["inputActionUser"]["userid"].value;
			}

			
			var xmlhttp;
			if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  	xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
			  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			    {
			    		document.getElementById("erroramount").innerHTML=xmlhttp.responseText;
			    }
			  }
			xmlhttp.open("GET","Controller.php?" + url,true);
			xmlhttp.send(null);
		}
	}